#include <Math.h>
#include "Camera.h"
#include "../HObject.h"
#include "../Math/Constants.h"

namespace helix{

	Camera::Camera() : HObject()
	{
		for(int i=0;i<3;i++)
		{
			position[i]=0;
			angles[i]=0;
		}
	}

	Camera::~Camera()
	{
	//	Log().Println("Camera Deleted.");
	}

	float Camera::x()
	{
		return position[0];
	}
	float Camera::y()
	{
		return position[1];
	}
	float Camera::z()
	{
		return position[2];
	}
	float *Camera::getPosition()
	{
		return position;
	}

	float Camera::xRot()
	{
		return angles[0];
	}
	float Camera::yRot()
	{
		return angles[1];
	}
	float Camera::zRot()
	{
		return angles[2];
	}

	void Camera::setX(float x)
	{
		position[0]=x;
	}
	void Camera::setY(float y)
	{
		position[1]=y;
	}
	void Camera::setZ(float z)
	{
		position[2]=z;
	}

	void Camera::setPosition(float x,float y,float z)
	{
		position[0]=x;
		position[1]=y;
		position[2]=z;
	}
	void Camera::setPosition(float *pos)
	{
		position[0]=pos[0];
		position[1]=pos[1];
		position[2]=pos[2];
	}

	void Camera::setXRot(float rads)
	{
		angles[0]=rads;
	}
	void Camera::setYRot(float rads)
	{
		angles[1]=rads;
	}
	void Camera::setZRot(float rads)
	{
		angles[2]=rads;
	}

	void Camera::addXRot(float rads)
	{
		angles[0]+=rads;
	}
	void Camera::addYRot(float rads)
	{
		angles[1]+=rads;
	}
	void Camera::addZRot(float rads)
	{
		angles[2]+=rads;
	}

	void Camera::trackTo(float *point, float *up)      //tracks the camera to point in space (up is the up vector)
	{
	}

	void Camera::trackTo(float *point)                 //simplified track to (uses <0,1,0> for the up vector)
	{
		angles[1]=(float)atan2(point[0]-position[0],point[2]-position[2]);
		if(point[2]-position[2]!=0)
			angles[0]=(float)atan((point[1]-position[1])/(point[2]-position[2]));
	}

	void Camera::trackTo(float x,float y,float z)      //simplified track to, using 3 floats for x,y,and z position of object
	{
		angles[1]=(float)atan2(x-position[0],z-position[2]);
		if(z-position[2]!=0)
			angles[0]=(float)atan((y-position[1])/(z-position[2]));
	}

	void Camera::Print()
	{
		Log().Println("Camera:: pos:(%f,%f,%f) eulers:(%f,%f,%f)",position[0],position[1],position[2],
																angles[0],angles[1],angles[2]);
	}

}